package com.zjyc.javaweb.service.impl;

import com.zjyc.javaweb.domain.po.User;
import com.zjyc.javaweb.service.UserService;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<User> getAllUser() {
        return jdbcTemplate.query("select * from users", new BeanPropertyRowMapper(User.class));
    }

    @Override
    public int addUser(User user) {
        return jdbcTemplate.update("insert into users(xh, name, age, pho, score) values(?, ?, ?, ?, ?)",
                user.getXh(), user.getName(), user.getAge(), user.getPhoto(), user.getScore());
    }
}
